package tt.dz.biz.dao.financial;

import java.util.List;
import org.springframework.stereotype.Repository;
import tt.dz.biz.dao.BaseDAO;
import tt.dz.common.DZStringUtil;
import tt.dz.vo.CostServiceMerchantVO;

@Repository("costServiceMerchantDAO")
public class CostServiceMerchantDAO
  extends BaseDAO
{
  private static final String LIST_ALL_COST_SERVICE_MERCHANT = "select  a.service_no,a.merchant_code,a.created_by,a.created_time,a.updated_by,a.updated_time,a.is_valid  from ms_cost_service_merchant as a where 1 =1 ";
  private static final String INSERT_COST_SERVICE_MERCHANT = "insert into ms_cost_service_merchant(service_no,merchant_code,created_by,created_time,updated_by,updated_time,is_valid)  values(:serviceNo,:merchantCode,:createdBy,:createdTime,:updatedBy,:updatedTime,:isValid )";
  private static final String UPDATE_COST_SERVICE_MERCHANT = "update  ms_cost_service_merchant set created_by = :createdBy,created_time = :createdTime,updated_by = :updatedBy,updated_time = :updatedTime,is_valid = :isValid where service_no = :serviceNo and merchant_code = :merchantCode ";
  
  public List<CostServiceMerchantVO> listAllCostServiceMerchant()
  {
    return queryForList("select  a.service_no,a.merchant_code,a.created_by,a.created_time,a.updated_by,a.updated_time,a.is_valid  from ms_cost_service_merchant as a where 1 =1 ", null, CostServiceMerchantVO.class);
  }
  
  public int insertCostServiceMerchant(CostServiceMerchantVO costServiceMerchantVO)
  {
    return save("insert into ms_cost_service_merchant(service_no,merchant_code,created_by,created_time,updated_by,updated_time,is_valid)  values(:serviceNo,:merchantCode,:createdBy,:createdTime,:updatedBy,:updatedTime,:isValid )", costServiceMerchantVO);
  }
  
  public int updateCostServiceMerchant(CostServiceMerchantVO costServiceMerchantVO)
  {
    return save("update  ms_cost_service_merchant set created_by = :createdBy,created_time = :createdTime,updated_by = :updatedBy,updated_time = :updatedTime,is_valid = :isValid where service_no = :serviceNo and merchant_code = :merchantCode ", costServiceMerchantVO);
  }
  
  public List<CostServiceMerchantVO> listCostServiceMerchantByCondition(CostServiceMerchantVO costServiceMerchantVO)
  {
    StringBuffer sb = new StringBuffer("select  a.service_no,a.merchant_code,a.created_by,a.created_time,a.updated_by,a.updated_time,a.is_valid  from ms_cost_service_merchant as a where 1 =1 ");
    if (costServiceMerchantVO != null)
    {
      if (!DZStringUtil.isEmpty(costServiceMerchantVO.getServiceNo())) {
        sb.append(" and service_no=:serviceNo");
      }
      if (!DZStringUtil.isEmpty(costServiceMerchantVO.getMerchantCode())) {
        sb.append(" and merchant_code=:merchantCode");
      }
      if (costServiceMerchantVO.getIsValid() != null) {
        sb.append(" and is_valid=:isValid");
      }
    }
    return queryForList(sb.toString(), costServiceMerchantVO, CostServiceMerchantVO.class);
  }
}
